<!DOCTYPE html>
<html lang="zh-CN" ng-app='he'>
	<head>
		<meta charset='utf-8' />
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>请假申请单</title>
		<script type="text/javascript">
			is_local='{{local}}';
			function loadjs(script_filename) {
		        document.write('\<script language="javascript" type="text/javascript" src="' + script_filename + '"\>\</script\>');
		    }
		    if(!is_local){
			    static_url='/static';
		    }else{
			    static_url='../../../../static';
		    }
		    // 加载所有微信页面需要的js和css
		    loadjs(static_url+'/js/weixin_page.js')
		</script>
		
		<script type="text/javascript">
			var app = angular.module('he',['ngSanitize']);
			app.config(function($interpolateProvider) {
				  $interpolateProvider.startSymbol('[[');
				  $interpolateProvider.endSymbol(']]');
				});
				
			app.controller('content',function ($scope,$http) {
				// 初始化变量
				if(is_local){
					$scope.this_left=0.34;
					$scope.last_left=2.3;
					$scope.swap_left=23.5;
				}else{
					// 从服务器初始化
					var post_url='/attendance/ajax/';
					function init_from_server() {
							//var leave=$scope.leave;
							var post_data = {
									get_annual_left:{},
									get_swap_left:{}
								};  
							$http.post(post_url,post_data)
							.success(function(data, status, headers, config) { 
								$scope.this_left=data.get_annual_left.this_left;
								$scope.last_left=data.get_annual_left.last_left;
								$scope.swap_left=data.get_swap_left.swap_left;
							}).error(function(data, status, headers, config) {  
							    //处理错误 
							    $scope.std='有错误,返回码为:'+status;
							});
					}
					init_from_server();	
				}
				$scope.category=''
				$scope.reason=''
				$scope.startdate=new Date();
				$scope.starthour='8';
				$scope.startminite='30';
				$scope.enddate=new Date();
				$scope.endhour='17';
				$scope.endminite='30';
				var submit_is_clicked=false;
				//--------提交服务器-----			
				$scope.submit=function () {
					submit_is_clicked=true;
					if(!$scope.form.$valid)return
					$scope.disable_submitBtn=true;
					var postData = {
							submit_leave:{category:$scope.category,
								start_time:get_start_time(),
								end_time:get_end_time(),
							reason:$scope.reason},
						};  
					$http.post(post_url,postData)
					.success(function(data, status, headers, config) { 
						var status=data.submit_leave.status;
						if (status=='success'){
							info('successful submit',function () {
								location='leave_info'
							})
						}else{
							info(data.submit_leave.msg)
							$scope.disable_submitBtn=false;
						}
						
					}).error(function(data, status, headers, config) {  
					    //处理错误 
					    $scope.std='有错误,返回码为:'+status;
					});
				}
				$scope.is_need_warn=function (name){
					if(!submit_is_clicked) return false
					return $scope.form[name].$error.required
				}
				$scope.get_class=function (name) {
					if($scope.is_need_warn(name)){
						return 'warn_border'
					}else{
						return ''
					}
				}
				$scope.get_leader_list=function () {
					if($scope.category){
						var postData = {
								get_app_check_name_list:{category:$scope.category,
														start_time:get_start_time(),
														end_time:get_end_time()
														},
							};  
						$http.post(post_url,postData)
						.success(function(data, status, headers, config) { 
							$scope.namelist=data.get_app_check_name_list.namelist
						}).error(function(data, status, headers, config) {  
						    //处理错误 
						    $scope.std='有错误,返回码为:'+status;
						});
					}

				}
				$scope.$watch('[category,startdate,starthour,startminite,enddate,endhour,endminite]',function (newval,oldval) {
						$scope.get_leader_list()
				})

				function get_start_time() {
					return date2str($scope.startdate)+' '+$scope.starthour+':'+$scope.startminite
				}
				function get_end_time() {
					return date2str($scope.enddate)+' '+$scope.endhour+':'+$scope.endminite
				}
			})
			
		function dt2str(dtobj) {
			return dtobj.getFullYear()+'-'+(dtobj.getMonth()+1)+'-'+dtobj.getDate()+" " +dtobj.getHours()+':'+dtobj.getMinutes()
		}
		function date2str(dateobj) {
			return dateobj.getFullYear()+'-'+(dateobj.getMonth()+1)+'-'+dateobj.getDate()
		}

		</script>
	<style type="text/css">
		.warn_fore{
			color: #ff6014;
		}
		.warn_border{
			border-color:#ff6014;
		}
	</style>
	</head>
	<body ng-controller='content'>
		<!-----------------弹出框------------------------>
		<div ng-include src='"info_panel.html"'></div>
		<!-----------------在这里填写内容------------------------>
	<div class="container">
        <div class="row">
            <div class="col-xs-12">
                <form role="form" name="form" class="leaveForm" novalidate>
                    <p style="color: #1686E2;font-size: 1.6em">假期申请</p>
                    <span style='float:right;'></span>

                    <div id="type">
                        <label class="tag">类型<i>*</i> </label>
                        <!-- ng-init="leave.category = 'select'"-->
                        <select class="form-control" 
                        	name="leaveType" 
                        	ng-model='category' 
                        	ng-class='get_class("leaveType")'  
                        	required>
                            <option value="">Select...</option>
                            <option value="annual_leave">年假</option>
                            <option value="personal_leave">事假</option>
                            <option value="sick_leave">病假</option>
                            <option value="birthday_leave">生日假</option>
                            <option value="swap_off">调休</option>
                            <option value="out_of">外出办公</option>
                            <option value="miss_check">漏打卡</option>
                            <option value="others">其他假期</option>
                        </select>
                        <span ng-show="is_need_warn('leaveType')" class='warn_fore'>必填选择申请类型</span>
                    </div>
                    <!------当选中年假和调休时，会显示相应的剩余时间---------->
                    <p ng-show="category=='annual_leave'" 
                    	class="hint">
                    	去年年假剩余：
                    	<span ng-bind='last_left'></span> 
                    	天；今年年假剩余
                    	<span ng-bind='this_left'></span>
                    	天
                    </p>
                    <p ng-show="category=='swap_off'" 
                    	class="hint">
                    	调休剩余
                    	<span ng-bind='swap_left'></span>
                    	小时
                    </p>
                    <div>
						<label class="tag">开始时间<i>*</i> </label>
						<div class="col-xs-12 clear">
							<input type="date" class="form-times col-xs-6" name="startdate" ng-model='startdate'/>
							<select class="form-times col-xs-3" style="margin: auto 5px" ng-model='starthour'>
								<option value="[[time]]"
									ng-repeat='time in [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]'>
									[[time]]
								</option>
							</select>
							<select class="form-times col-xs-2" ng-model='startminite'>
								<option value="00">00</option>
								<option value="30">30</option>
							</select>
						</div>
                        <!--<span ng-show="is_need_warn('startTime')" class='warn_fore'>必填选择申请的开始时间</span>-->
                    </div>
                    <div  class="col-xs-12 clear">
                        <label class="tag">结束时间<i>*</i> </label>
                        <!--<input type="datetime-local" class="form-control" name="endTime" ng-model='leave.end_time' ng-class='get_class("endTime")' required/>-->
                        <input type="date" class="form-times col-xs-6" name="enddate" ng-model='enddate'/>
						<select class="form-times col-xs-3" style="margin: auto 5px" ng-model='endhour'>
							<option value="[[time]]"
								ng-repeat='time in [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]'>
								[[time]]
							</option>
						</select>
						<select class="form-times col-xs-2" ng-model='endminite'>
							<option value="00">00</option>
							<option value="30">30</option>
						</select>
						
                        <!--<span ng-show="is_need_warn('endTime')" class='warn_fore'>必填选择申请的结束时间</span>-->
                    </div>
                    <div style="clear: both">
                        <label class="tag">原因<i>*</i></label>
                        <!-- [true] leave.reason==""  ng-class='{false:"normal",true:"warn"}[leave.reason==""]'-->
                        <textarea ng-class='get_class("reason")' 
                        	class="form-control" 
                        	name='reason'  
                        	ng-model='reason' 
                        	required>
                        </textarea>
                        <span ng-show="is_need_warn('reason')" class='warn_fore'>必填填写原因</span>
                    </div>
                    <div>
                        <label class="tag">审批人</label>
                        <div class="approverBox">
	                        <span class="approverName" 
	                        	ng-repeat='name in namelist' 
	                        	ng-bind='name'>
	                        </span>
                            <!--<span class="approverName">Echo</span>
                            <span class="approverName">Liuhailong</span>-->
                        </div>
                    </div>
                    <!-- onclick="checkAll()"-->
                    <div style='margin-top: 20px;margin-bottom:200px;'>
	                    <button type="button" class="btn btn-primary" ng-disabled='disable_submitBtn' ng-click='submit()'>提交</button>
                    </div>
                    
                </form>
            </div>
        </div>
    </div>

	</body>
</html>